﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using Bangle.Model;

namespace Bangle.BLL
{
    //T_Phone
    public partial class T_PhoneBLL
    {

        private readonly Bangle.DAL.T_PhoneDAL dal = new Bangle.DAL.T_PhoneDAL();
        public T_PhoneBLL()
        { }

        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(Guid PhoneId)
        {
            return dal.Exists(PhoneId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Bangle.Model.T_Phone model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Bangle.Model.T_Phone model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Guid PhoneId)
        {

            return dal.Delete(PhoneId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Bangle.Model.T_Phone GetModel(Guid PhoneId)
        {
            return dal.GetModel(PhoneId);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Bangle.Model.T_Phone GetModelByCache(Guid PhoneId)
        {

            string CacheKey = "T_PhoneModel-" + PhoneId;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(PhoneId);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Bangle.Model.T_Phone)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Bangle.Model.T_Phone> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Bangle.Model.T_Phone> DataTableToList(DataTable dt)
        {
            List<Bangle.Model.T_Phone> modelList = new List<Bangle.Model.T_Phone>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Bangle.Model.T_Phone model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Bangle.Model.T_Phone();
                    if (dt.Rows[n]["PhoneId"].ToString() != "")
                    {
                        model.PhoneId = new Guid(dt.Rows[n]["PhoneId"].ToString());
                    }
                    model.PhoneName = dt.Rows[n]["PhoneName"].ToString();
                    model.PhoneCode = dt.Rows[n]["PhoneCode"].ToString();
                    if (dt.Rows[n]["SupplierId"].ToString() != "")
                    {
                        model.SupplierId = new Guid(dt.Rows[n]["SupplierId"].ToString());
                    }
                    if (dt.Rows[n]["RMB"].ToString() != "")
                    {
                        model.RMB = decimal.Parse(dt.Rows[n]["RMB"].ToString());
                    }
                    model.PartNo = dt.Rows[n]["PartNo"].ToString();
                    model.Specification = dt.Rows[n]["Specification"].ToString();
                    if (dt.Rows[n]["USD"].ToString() != "")
                    {
                        model.USD = decimal.Parse(dt.Rows[n]["USD"].ToString());
                    }
                    if (dt.Rows[n]["PCS"].ToString() != "")
                    {
                        model.PCS = decimal.Parse(dt.Rows[n]["PCS"].ToString());
                    }
                    if (dt.Rows[n]["CreateUserId"].ToString() != "")
                    {
                        model.CreateUserId = int.Parse(dt.Rows[n]["CreateUserId"].ToString());
                    }
                    model.CreateTime = dt.Rows[n]["CreateTime"].ToString();
                    if (dt.Rows[n]["UpdateUserId"].ToString() != "")
                    {
                        model.UpdateUserId = int.Parse(dt.Rows[n]["UpdateUserId"].ToString());
                    }
                    model.UpdateTime = dt.Rows[n]["UpdateTime"].ToString();
                    if (dt.Rows[n]["Valid"].ToString() != "")
                    {
                        model.Valid = int.Parse(dt.Rows[n]["Valid"].ToString());
                    }
                    if (dt.Rows[n]["ScreenId"].ToString() != "")
                    {
                        model.ScreenId = int.Parse(dt.Rows[n]["ScreenId"].ToString());
                    }
                    if (dt.Rows[n]["ChipId"].ToString() != "")
                    {
                        model.ChipId = int.Parse(dt.Rows[n]["ChipId"].ToString());
                    }
                    if (dt.Rows[n]["SeriesId"].ToString() != "")
                    {
                        model.SeriesId = int.Parse(dt.Rows[n]["SeriesId"].ToString());
                    }
                    model.SalePoint = dt.Rows[n]["SalePoint"].ToString();


                    modelList.Add(model);
                }
            }
            return modelList;
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }


        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }


        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        #endregion

    }
}